<?php
declare (strict_types=1);

namespace app\datacenter\controller;

use app\BaseController;
use app\datacenter\service\LargeScreenService;
use emqx\EmqxHttpApi;
use think\response\Json;

/**
 * 大屏
 */
class LargeScreen extends BaseController
{


    /**
     * 设备模块数据（出袋数，设备在线数，设备离线数，在线百分比）
     * @param LargeScreenService $largeScreenService
     * @return Json
     */
    public function equipment(LargeScreenService $largeScreenService): Json
    {
        $todayDate = date('Y-m-d', time());
        $redis_city_key = config('ws_config.redis_key')['datacenter_statistics_city_list'] . $todayDate;
        $redis = RedisTools::getInstance(config('cache.stores')['redis'], 0)->getRedis();
        $list = $redis->zRevRange($redis_city_key, 0, 4, true);
        dump($list);
        die;
        $MqttClient = new EmqxHttpApi();
        $res = $MqttClient->publish($MqttClient->emqx_datacenter_username, ['name' => '测试', 'price' => 0.01, 'city' => '广州', 'mac_id' => 80036]);
        dump($res);
        die;

        $data = request()->param();
        if (isset($data['type'])) {
            $type = intval($data['type']);
            if ($type) {
                $data = $largeScreenService->getData($type);
                $MqttClient = new EmqxHttpApi();
                $res = $MqttClient->publish($MqttClient->emqx_datacenter_username, $data);

            }
        }

        return jsonReturn(1, $data);
    }
}
